﻿#include "MyPasswordFile.h"
#include <QApplication>
#include <QDataStream>
#include <QFile>

MyPasswordFile::MyPasswordFile(QObject *parent) : QObject(parent)
{
    m_passWord = "";
}

MyPasswordFile::MyPasswordFile(QString password, QObject *parent) : QObject(parent)
{
    m_passWord = password;
}


QString MyPasswordFile::password()
{
    return m_passWord;
}

bool MyPasswordFile::store()
{
    QFile file(QApplication::applicationDirPath() + "/Password.conf");

    bool ret = true;

    if( file.open(QIODevice::WriteOnly) )
    {
        QDataStream out(&file);
        out << m_passWord;
        file.close();
    }
    else
    {
        ret = false;
    }
    return ret;
}

bool MyPasswordFile::restore()
{
    QFile file(QApplication::applicationDirPath() + "/Password.conf");
    bool ret = true;
    if( file.open(QIODevice::ReadOnly ) )
    {
        QDataStream in(&file);
        in >> m_passWord;
        file.close();
    }
    else
    {
        ret = false;
    }
    return ret;
}


